package edu.bit.water.service;

import java.text.DecimalFormat;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;

import edu.bit.water.dao.EntityEvaCmpWaterAnlDao;
import edu.bit.water.dao.LabelEvaCmpWaterAnlDao;
import edu.bit.water.entity.EntityEvaCmpWaterAnl;
import edu.bit.water.entity.LabelEvaCmpWaterTAndASum;

/**
 * 水平衡用水实体表业务层
 * @author HJS
 *
 */
@Service
public class EntityEvaCmpWaterAnlService {

	private DecimalFormat df = new DecimalFormat("#.0");

	@Autowired
	private EntityEvaCmpWaterAnlDao entityEvaCmpWaterAnlDao;
	@Autowired
	private LabelEvaCmpWaterAnlDao labelEvaCmpWaterAnlDao;
	@Autowired
	private EntityWaterService entityWaterService;

	/**
	 *
	 * @param entityEvaCmpWaterAnl  企业用水分析实体表
	 * @return 成功返回1，失败返回0
	 * @throws Exception
	 */
	@Transactional
	public Map<String, String>  add(EntityEvaCmpWaterAnl entityEvaCmpWaterAnl){
		Map<String, String> map = new HashMap<>();
		//条件成立说明是生产用水
		int flag = 0;
		int n = 0;
		if (entityEvaCmpWaterAnl.getLocation().equals("生产用水")) {
			try {
				n = entityEvaCmpWaterAnlDao.addPro(entityEvaCmpWaterAnl);
			} catch (DuplicateKeyException e) {
				// TODO: handle exception
				if (e.getMessage().indexOf("CLASSANDUSING_UNIQUE") != -1) {
					map.put("status", "failed");
					map.put("msg", "用水分类和用水用途已重复，请重新输入");
					return map;
				}
			}
			if (n == 1) {
				LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnl.getLabelId());
				if (labelEvaCmpWaterTAndASum !=null) {
					labelEvaCmpWaterTAndASum.setUseWaterSuml(labelEvaCmpWaterTAndASum.getUseWaterSuml()+entityEvaCmpWaterAnl.getUseWater());
					labelEvaCmpWaterTAndASum.setNewWaterSuml(labelEvaCmpWaterTAndASum.getNewWaterSuml()+entityEvaCmpWaterAnl.getNewWater());
					labelEvaCmpWaterTAndASum.setRepeatWaterSuml(labelEvaCmpWaterTAndASum.getRepeatWaterSuml()+entityEvaCmpWaterAnl.getRepeatWater());
					labelEvaCmpWaterTAndASum.setDrainWaterSuml(labelEvaCmpWaterTAndASum.getDrainWaterSuml()+entityEvaCmpWaterAnl.getDrainWater());
					labelEvaCmpWaterTAndASum.setConsumpWaterSuml(labelEvaCmpWaterTAndASum.getConsumpWaterSuml()+entityEvaCmpWaterAnl.getConsumpWater());
					labelEvaCmpWaterTAndASum.setLossWaterSuml(labelEvaCmpWaterTAndASum.getLossWaterSuml()+entityEvaCmpWaterAnl.getLossWater());
					labelEvaCmpWaterTAndASum.setCompany_id(entityEvaCmpWaterAnl.getLabelId());
//0309					//取水量为企业水平衡测试统计表的常规水资源量汇总量
//					labelEvaCmpWaterTAndASum.calWater1Sum();
//					labelEvaCmpWaterTAndASum.calculateValue();
					flag = labelEvaCmpWaterAnlDao.updateSum(labelEvaCmpWaterTAndASum);
				}
				else{
					labelEvaCmpWaterTAndASum = new LabelEvaCmpWaterTAndASum();
//					System.out.println(entityEvaCmpWaterAnl.getUseWater());
//					System.out.println(entityEvaCmpWaterAnl.getLabelId());
					labelEvaCmpWaterTAndASum.setUseWaterSuml(entityEvaCmpWaterAnl.getUseWater());
					labelEvaCmpWaterTAndASum.setNewWaterSuml(entityEvaCmpWaterAnl.getNewWater());
					labelEvaCmpWaterTAndASum.setRepeatWaterSuml(entityEvaCmpWaterAnl.getRepeatWater());
					labelEvaCmpWaterTAndASum.setDrainWaterSuml(entityEvaCmpWaterAnl.getDrainWater());
					labelEvaCmpWaterTAndASum.setConsumpWaterSuml(entityEvaCmpWaterAnl.getConsumpWater());
					labelEvaCmpWaterTAndASum.setLossWaterSuml(entityEvaCmpWaterAnl.getLossWater());
					labelEvaCmpWaterTAndASum.setCompany_id(entityEvaCmpWaterAnl.getLabelId());
//0309					//计算取水量
//					labelEvaCmpWaterTAndASum.calWater1Sum();
//					labelEvaCmpWaterTAndASum.calculateValue();
					flag = labelEvaCmpWaterAnlDao.insertSum(labelEvaCmpWaterTAndASum);
				}
			}
		}
		//如果为0，则是非生产用水
		else if (entityEvaCmpWaterAnl.getLocation().equals("非生产用水")) {
			n= entityEvaCmpWaterAnlDao.addNonPro(entityEvaCmpWaterAnl);
			if (n == 1) {
				LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnl.getLabelId());
				labelEvaCmpWaterTAndASum.setUseWaterSumn(labelEvaCmpWaterTAndASum.getUseWaterSumn()+entityEvaCmpWaterAnl.getUseWater());
				labelEvaCmpWaterTAndASum.setNewWaterSumn(labelEvaCmpWaterTAndASum.getNewWaterSumn()+entityEvaCmpWaterAnl.getNewWater());
				labelEvaCmpWaterTAndASum.setCompany_id(entityEvaCmpWaterAnl.getLabelId());

//0309				//计算取水量
//				labelEvaCmpWaterTAndASum.calWater1Sum();
//				labelEvaCmpWaterTAndASum.calculateValue();

				flag = labelEvaCmpWaterAnlDao.updateSum(labelEvaCmpWaterTAndASum);
			}
			else{
				LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnl.getLabelId());
				labelEvaCmpWaterTAndASum.setUseWaterSumn(entityEvaCmpWaterAnl.getUseWater());
				labelEvaCmpWaterTAndASum.setNewWaterSumn(entityEvaCmpWaterAnl.getNewWater());
				labelEvaCmpWaterTAndASum.setCompany_id(entityEvaCmpWaterAnl.getLabelId());

//0309				//计算取水量
//				labelEvaCmpWaterTAndASum.calWater1Sum();
//				labelEvaCmpWaterTAndASum.calculateValue();
				flag = labelEvaCmpWaterAnlDao.insertSum(labelEvaCmpWaterTAndASum);
			}
		}
		if (n == 1) {
			map.put("status", "success");
		}
		else
			map.put("status", "failed");
		return map;
	}
	/**
	 *
	 * @param idLists 要删除记录的id集合
	 * @return 成功返回1，失败返回0
	 */
	@Transactional
	public int delete(List<Integer> idLists) {
		try {
			for (int id : idLists) {
				//1.先查询水平衡表中将要被删除记录的值
				EntityEvaCmpWaterAnl entityEvaCmpWaterAnl = entityEvaCmpWaterAnlDao.selectOne(id);
				//2.删除记录
				int n = entityEvaCmpWaterAnlDao.delete(id);
				//2.判断它是生产用水还是非成产用水
				if (n == 1) {
					//2.1此时是生产用水
					if (entityEvaCmpWaterAnl.getLocation().equals("生产用水")) {
						LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnl.getLabelId());
						labelEvaCmpWaterTAndASum.setUseWaterSuml(labelEvaCmpWaterTAndASum.getUseWaterSuml()-entityEvaCmpWaterAnl.getUseWater());
						labelEvaCmpWaterTAndASum.setNewWaterSuml(labelEvaCmpWaterTAndASum.getNewWaterSuml()-entityEvaCmpWaterAnl.getNewWater());
						labelEvaCmpWaterTAndASum.setRepeatWaterSuml(labelEvaCmpWaterTAndASum.getRepeatWaterSuml()-entityEvaCmpWaterAnl.getRepeatWater());
						labelEvaCmpWaterTAndASum.setDrainWaterSuml(labelEvaCmpWaterTAndASum.getDrainWaterSuml()-entityEvaCmpWaterAnl.getDrainWater());
						labelEvaCmpWaterTAndASum.setConsumpWaterSuml(labelEvaCmpWaterTAndASum.getConsumpWaterSuml()-entityEvaCmpWaterAnl.getConsumpWater());
						labelEvaCmpWaterTAndASum.setLossWaterSuml(labelEvaCmpWaterTAndASum.getLossWaterSuml()-entityEvaCmpWaterAnl.getLossWater());
//0309						labelEvaCmpWaterTAndASum.calWater1Sum();//计算取水量
//						labelEvaCmpWaterTAndASum.calculateValue();
						labelEvaCmpWaterAnlDao.updateSum(labelEvaCmpWaterTAndASum);
					}
					else if (entityEvaCmpWaterAnl.getLocation().equals("非生产用水")) {
						LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnl.getLabelId());
						labelEvaCmpWaterTAndASum.setUseWaterSumn(labelEvaCmpWaterTAndASum.getUseWaterSumn()-entityEvaCmpWaterAnl.getUseWater());
						labelEvaCmpWaterTAndASum.setNewWaterSumn(labelEvaCmpWaterTAndASum.getNewWaterSumn()-entityEvaCmpWaterAnl.getNewWater());
//0309						labelEvaCmpWaterTAndASum.calWater1Sum();
//						labelEvaCmpWaterTAndASum.calculateValue();
						labelEvaCmpWaterAnlDao.updateSum(labelEvaCmpWaterTAndASum);
					}
				}
			}
			return 1;
		} catch (Exception e) {
			// TODO: handle exception
			return 0;
		}
	}
	/**
	 *
	 * @param entityEvaCmpWaterAnl 企业用水分析实体表
	 * @return 成功返回1，失败返回0
	 */
	@Transactional
	public Map<String, String> update(EntityEvaCmpWaterAnl entityEvaCmpWaterAnl) {
		Map<String, String> map = new HashMap<>();
		int n = 0;
		try {
			//1.先查询水平衡表中将要被更新记录的值
			EntityEvaCmpWaterAnl entityEvaCmpWaterAnlTemp = entityEvaCmpWaterAnlDao.selectOne(entityEvaCmpWaterAnl.getId());
			try {
				n= entityEvaCmpWaterAnlDao.update(entityEvaCmpWaterAnl);
			} catch (DuplicateKeyException e) {
				// TODO: handle exception
				if (e.getMessage().indexOf("CLASSANDUSING_UNIQUE") != -1) {
					map.put("status", "failed");
					map.put("msg", "用水分类和用水用途已重复，请重新输入");
					return map;
				}
			}
			//2.判断它是生产用水还是非成产用水
			if (n == 1) {
				//2.1此时是生产用水
				if (entityEvaCmpWaterAnlTemp.getLocation().equals("生产用水")) {
					LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnlTemp.getLabelId());
					labelEvaCmpWaterTAndASum.setUseWaterSuml(labelEvaCmpWaterTAndASum.getUseWaterSuml()+entityEvaCmpWaterAnl.getUseWater()-entityEvaCmpWaterAnlTemp.getUseWater());
					labelEvaCmpWaterTAndASum.setNewWaterSuml(labelEvaCmpWaterTAndASum.getNewWaterSuml()+entityEvaCmpWaterAnl.getNewWater()-entityEvaCmpWaterAnlTemp.getNewWater());
					labelEvaCmpWaterTAndASum.setRepeatWaterSuml(labelEvaCmpWaterTAndASum.getRepeatWaterSuml()+entityEvaCmpWaterAnl.getRepeatWater()-entityEvaCmpWaterAnlTemp.getRepeatWater());
					labelEvaCmpWaterTAndASum.setDrainWaterSuml(labelEvaCmpWaterTAndASum.getDrainWaterSuml()+entityEvaCmpWaterAnl.getDrainWater()-entityEvaCmpWaterAnlTemp.getDrainWater());
					labelEvaCmpWaterTAndASum.setConsumpWaterSuml(labelEvaCmpWaterTAndASum.getConsumpWaterSuml()+entityEvaCmpWaterAnl.getConsumpWater()-entityEvaCmpWaterAnlTemp.getConsumpWater());
					labelEvaCmpWaterTAndASum.setLossWaterSuml(labelEvaCmpWaterTAndASum.getLossWaterSuml()+entityEvaCmpWaterAnl.getLossWater()-entityEvaCmpWaterAnlTemp.getLossWater());
//0309					labelEvaCmpWaterTAndASum.calWater1Sum();//计算取水量
//					labelEvaCmpWaterTAndASum.calculateValue();
					labelEvaCmpWaterAnlDao.updateSum(labelEvaCmpWaterTAndASum);
				}
				else if (entityEvaCmpWaterAnl.getLocation().equals("非生产用水")) {
					LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectSum(entityEvaCmpWaterAnlTemp.getLabelId());
					labelEvaCmpWaterTAndASum.setUseWaterSumn(labelEvaCmpWaterTAndASum.getUseWaterSumn()+entityEvaCmpWaterAnl.getUseWater()-entityEvaCmpWaterAnlTemp.getUseWater());
					labelEvaCmpWaterTAndASum.setNewWaterSumn(labelEvaCmpWaterTAndASum.getNewWaterSumn()+entityEvaCmpWaterAnl.getNewWater()-entityEvaCmpWaterAnlTemp.getNewWater());
//0309					labelEvaCmpWaterTAndASum.calWater1Sum();//计算取水量
//					labelEvaCmpWaterTAndASum.calculateValue();
					labelEvaCmpWaterAnlDao.updateSum(labelEvaCmpWaterTAndASum);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		if (n == 1) {
			map.put("status", "success");
		}
		else
			map.put("status", "failed");
		return map;
	}
	/**
	 *
	 * @param labelId 水分析表记录外键，也就是对应的标签表id
	 * @return 成功返回所有记录，失败或者没有记录返回null
	 */
	public List<EntityEvaCmpWaterAnl> select(int labelId){
		List<EntityEvaCmpWaterAnl> list = entityEvaCmpWaterAnlDao.select(labelId);
		Collections.sort(list);
		return list;
	}
	/**
	 * 在计算之间先返回是否已有值
	 * @param rid	标签表的id
	 * @param count		公式id(确定第几个公式)
	 * @return 返回json数据
	 */
	public JSONObject selectResult(int rid,int count) {
		Map<String,Object> map = new HashMap<>();
		JSONObject jsonObject = new JSONObject();
		String sum = null;
		switch(count) {
			case 1:		sum = "sum1_data"; 	break;
			case 2:		sum = "sum2_data"; 	break;
			case 3:		sum = "sum3_data"; 	break;
			case 4:		sum = "sum4_data"; 	break;
			case 5:		sum = "sum5_data"; 	break;
			case 6:		sum = "sum6_data"; 	break;
			case 7:		sum = "sum7_data"; 	break;
			case 8:		sum = "sum8_data"; 	break;
			case 9:		sum = "sum9_data"; 	break;
			case 10:	sum = "sum10_data"; break;
		}
		LabelEvaCmpWaterTAndASum labelEvaCmpWaterTAndASum = labelEvaCmpWaterAnlDao.selectResult(sum, rid);
		if (count == 1) {
			if (labelEvaCmpWaterTAndASum.getSum1_data() == null ) {
				jsonObject.put("sumResult", null);
				map.put("param1", labelEvaCmpWaterTAndASum.getWater1Sum());
				JSONObject paramJson = new JSONObject(map);
				jsonObject.put("param",paramJson);
			}
			else
				jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum1_data()));
		}else if (count == 4) {
			if (labelEvaCmpWaterTAndASum.getSum4_data() == null ) {
				jsonObject.put("sumResult", null);
				map.put("param1", labelEvaCmpWaterTAndASum.getLossWaterSuml());
				map.put("param2", labelEvaCmpWaterTAndASum.getNewWaterSuml());
				JSONObject paramJson = new JSONObject(map);
				jsonObject.put("param",paramJson);
			}
			else
				jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum1_data()));
		}else if (count == 6) {
			if (labelEvaCmpWaterTAndASum.getSum6_data() == null ) {
				jsonObject.put("sumResult", null);
				map.put("param1", labelEvaCmpWaterTAndASum.getRepeatWaterSuml());
				map.put("param2", labelEvaCmpWaterTAndASum.getNewWaterSuml());
				JSONObject paramJson = new JSONObject(map);
				jsonObject.put("param",paramJson);
			}
			else
				jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum1_data()));
		}else if (count == 8) {
			if (labelEvaCmpWaterTAndASum.getSum8_data() == null ) {
				jsonObject.put("sumResult", null);
				map.put("param2", labelEvaCmpWaterTAndASum.getNewWaterSuml());
				JSONObject paramJson = new JSONObject(map);
				jsonObject.put("param",paramJson);
			}
			else
				jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum1_data()));
		}else if (count == 10) {
			if (labelEvaCmpWaterTAndASum.getSum10_data() == null ) {
				jsonObject.put("sumResult", null);
				map.put("param1", labelEvaCmpWaterTAndASum.getUnconWaterUse());
				map.put("param2", labelEvaCmpWaterTAndASum.getGetWater());
				JSONObject paramJson = new JSONObject(map);
				jsonObject.put("param",paramJson);
			}
			else
				jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum1_data()));
		}else {
			switch(count) {
				case 2:	jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum2_data())); break;
				case 3: jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum3_data())); break;
				case 5: jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum5_data())); break;
				case 7: jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum7_data())); break;
				case 9: jsonObject.put("sumResult", JSONObject.parse(labelEvaCmpWaterTAndASum.getSum9_data())); break;
				default:break;
			}
		}
		return jsonObject;
	}
	/**
	 *
	 * @param id 标签id
	 * @param count 哪个公式
	 * @param jsonObject josn数据
	 * @return 返回json
	 */
	public JSONObject calculateResult(int id,int count,JSONObject jsonObject) {
		JSONObject variableOne = jsonObject.getJSONObject("one");
		JSONObject variableTwo = jsonObject.getJSONObject("two");
		JSONObject testTime = jsonObject.getJSONObject("time");
		Date[] startTimes = testTime.getObject("startTime", Date[].class);
		Date[] endTimes = testTime.getObject("endTime", Date[].class);
		int timesLength = startTimes.length;
		double variablOneAverage = 0;
		double variablTwoAverage = 0;
		if (variableOne.getIntValue("type") == 0) { // 第二个参数type等于0时，是自动录入
			String[] sensor_ids = variableOne.getJSONObject("position").getObject("sensor_id", String[].class);
			JSONObject jsonReslutTemp = deltaComputer(sensor_ids,timesLength,startTimes,endTimes);
			variableOne.replace("delta", jsonReslutTemp.get("arr"));
			variablOneAverage = jsonReslutTemp.getDoubleValue("sum")/timesLength;
		}
		else{ // 等于1时，是手工录入，等于2时是固定值
			variablOneAverage = variableOne.getDoubleValue("average");
		}
		if (variableTwo.getIntValue("type") == 0) {
			String[] sensor_ids = variableTwo.getJSONObject("position").getObject("sensor_id", String[].class);
			JSONObject jsonReslutTemp = deltaComputer(sensor_ids,timesLength,startTimes,endTimes);
			variableTwo.replace("delta", jsonReslutTemp.get("arr"));
			variablTwoAverage = jsonReslutTemp.getDoubleValue("sum")/timesLength;
		}
		else { // 等于1时，是手工录入，等于2时是固定值
			variablTwoAverage = variableTwo.getDoubleValue("average");
		}
		variableOne.replace("average", variablOneAverage);
		variableTwo.replace("average", variablTwoAverage);
		if (variablTwoAverage == 0 || (variablOneAverage+variablTwoAverage) == 0) {
			jsonObject.replace("result",null);
		}
		else {
			double result = 0;
			if (count == 1) {
				result = variablOneAverage/variablTwoAverage;
				jsonObject.replace("result",result);
				String sum_data = jsonObject.toString();
				labelEvaCmpWaterAnlDao.updateFormula1(id, variablTwoAverage, result, sum_data);
			}
			else {
				if (count == 6 || count == 7) {
					result = variablOneAverage/(variablOneAverage + variablTwoAverage);
				}
				else {
					result = variablOneAverage/variablTwoAverage;
				}
				String retString = df.format(result*100)+"%";
				jsonObject.replace("result",retString);
				String sum_data = jsonObject.toString();
				switch(count) {
					case 2:	labelEvaCmpWaterAnlDao.updateFormula2(id,variablOneAverage , variablTwoAverage , retString, sum_data); break;
					case 3: labelEvaCmpWaterAnlDao.updateFormula3(id,variablOneAverage , variablTwoAverage , retString, sum_data); break;
					case 4: labelEvaCmpWaterAnlDao.updateFormula4(id, retString,sum_data); break;
					case 5: labelEvaCmpWaterAnlDao.updateFormula5(id, variablOneAverage, variablTwoAverage, retString, sum_data); break;
					case 6: labelEvaCmpWaterAnlDao.updateFormula6(id, retString, sum_data); break;
					case 7: labelEvaCmpWaterAnlDao.updateFormula7(id, variablOneAverage, variablTwoAverage, retString, sum_data); break;
					case 8: labelEvaCmpWaterAnlDao.updateFormula8(id, variablTwoAverage, retString, sum_data); break;
					case 9: labelEvaCmpWaterAnlDao.updateFormula9(id, variablOneAverage, variablTwoAverage, retString, sum_data); break;
					case 10:labelEvaCmpWaterAnlDao.updateFormula10(id, retString, sum_data);
					default:break;
				}
			}
			String retString = df.format(result*100)+"%";
			jsonObject.replace("result",retString);
			String sum_data = jsonObject.toString();
			switch(count) {
				case 2:	labelEvaCmpWaterAnlDao.updateFormula2(id,variablOneAverage , variablTwoAverage , retString, sum_data); break;
				case 3: labelEvaCmpWaterAnlDao.updateFormula3(id,variablOneAverage , variablTwoAverage , retString, sum_data); break;
				case 4: labelEvaCmpWaterAnlDao.updateFormula4(id, retString,sum_data); break;
				case 5: labelEvaCmpWaterAnlDao.updateFormula5(id, variablOneAverage, variablTwoAverage, retString, sum_data); break;
				case 6: labelEvaCmpWaterAnlDao.updateFormula6(id, retString, sum_data); break;
				case 7: labelEvaCmpWaterAnlDao.updateFormula7(id, variablOneAverage, variablTwoAverage, retString, sum_data); break;
				case 8: labelEvaCmpWaterAnlDao.updateFormula8(id, variablTwoAverage, retString, sum_data); break;
				case 9: labelEvaCmpWaterAnlDao.updateFormula9(id, variablOneAverage, variablTwoAverage, retString, sum_data); break;
				case 10:labelEvaCmpWaterAnlDao.updateFormula10(id, retString, sum_data);
				default:break;
			}
		}
		return jsonObject;
	}
	public JSONObject deltaComputer(String[] sensor_ids, int startTimesLength, Date[] startTimes, Date[] endTimes) {
		double[] arr = new double[startTimesLength];
		int index = 0;
		double sum = 0;
		for(int i = 0;i < startTimesLength; i++) { //计录每一组时间的差值
			Double result = entityWaterService.subtraction(sensor_ids, startTimes[i], endTimes[i]);
			if (result != null) {
				sum += result;
				arr[index++] = result;
			}
		}
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("sum", sum);
		jsonObject.put("arr", arr);
		return jsonObject;
	}
}
